/**
 * Copyright 2016 JustWayward Team
 * <p/>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p/>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p/>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.ljfiction.book.readview;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.Typeface;
import android.graphics.drawable.GradientDrawable;
import android.support.v4.content.ContextCompat;
import android.text.TextPaint;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ProgressBar;


import com.lidroid.xutils.util.LogUtils;
import com.ljfiction.book.Baner.Bookchapters;
import com.ljfiction.book.Baner.ChapterContext;
import com.ljfiction.book.Baner.ReadBaocunBean;
import com.ljfiction.book.Baner.ReadBeijingBean;
import com.ljfiction.book.R;
import com.ljfiction.book.tools.AppUtils;
import com.ljfiction.book.http.UserManageBean;
import com.ljfiction.book.tools.ScreenUtils;
import com.ljfiction.book.tools.SettingManager;


import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Vector;

public class PageFactory {
    private Context mContext;
    /*
     * mHeight：        屏幕的总高度
     * mWidth：         屏幕减去段评的宽度
     * daWidth：        屏幕的宽度
     * mVisibleHeight： 显示文字的高度
     * mVisibleWidth：  显示文字的宽度
     * marginHeight：   上下空余空间
     * marginWidth：    左右空域空间
     *mNumFontSize:     顶部底部字体大小
     * mFontSize:       正文字体大小
     * mLineSpace:      行间距
     * mPageLineCount： 每页的行数
     * mbBufferLen：    本章节字节长度
     * curEndPos：      页尾的位置
     * curBeginPos：    页首的位置
     * tempBeginPos：   记录页首的位置
     * tempEndPos：     记录页尾的位置
     *currentChapter:   本章节所在下标
     * tempChapter：    记录上一章节所在下标
     * timeLen:         时间的长度
     * percentLen：     百分比的长度
     * battery:         电池的长度
     * chapterSize:     章节的数量
     * currentPage：    当前页数
     * tempPage：       保存当前页数
     * baocundiannum：  当前章节保存的右边段评实体类的数量
     * zidongBitmapWight:自动订阅的宽
     * zidongBitmapHeight：自动订阅的高
     * authorNum:       预留作者的话的高度
     * authorImagerec:  作者头像的直径;
     * */
    private int mHeight, mWidth, daWidth, mVisibleHeight, mVisibleWidth, marginHeight, marginWidth, mFontSize, mNumFontSize,mLineSpace,mPageLineCount,mbBufferLen
    ,curEndPos = 0, curBeginPos = 0, tempBeginPos, tempEndPos,currentChapter, tempChapter,timeLen = 0, percentLen = 0,battery = 40,chapterSize = 0
    ,currentPage = 1, tempPage = 1,baocundiannum = 0, zidongBitmapWight, zidongBitmapHeight,authorNum = 0, authorImagerec = 30;

    /**
     * ByteBuffer：高效的文件内存映射
     */
    private ByteBuffer mbBuff;
    private Vector<String> mLines = new Vector<>();
    /*
     *mPaint:            正文字
     *authorPain:        作者的话字
     * mPaintVIP:        VIP里的字
     *mPaintyue:         余额
     * mPaintVIPbuy:     购买
     * mTitlePaint:      顶部和底部显示的字和时间
     * mdiannum:         右边段评条数
     *mDuanpingPaint:    右边段评的竖线
     * mpark：           右边段评的⚪
     * smallmpark：      右边段评的小⚪
     *mchapterPage：     首页的章节标题
     * vipPaint:         订阅的按钮
     * mRectvip：        VIP矩形
     *mPaintInvite       vip中邀请好友
     * */
    private Paint  authorPaint, mPaintVIP, mPaintyue, mPaintVIPbuy, mTitlePaint, mdiannum, mDuanpingPaint, mpark, smallmpark, mchapterPage, vipPaint, mRectvip,mPaintInvite;//
    private TextPaint mPaint;
    /*
     * mBookPageBg:      阅读也背景
     * batteryBitmap：   电池
     * authorImageBitmap:获取作者的头像图片
     * ahthorbackBitmap: 获取作者的话背景图
     * bitmapvip:        vip图片
     * iszidongVip       自动图片
     * nozidongVip       非自动图片;
     * */
    private Bitmap mBookPageBg, batteryBitmap, authorImageBitmap, authorbackBitmap, bitmapvip, iszidongVip, nozidongVip;

    /*
     * 背景颜色
     * */
    private ReadBeijingBean readBeijingBean = new ReadBeijingBean();

    private DecimalFormat decimalFormat = new DecimalFormat("#0.00");
    private SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm");

    private Rect rectF, dianchi;
    private ProgressBar batteryView;
    private Map<Integer, List<Baocunduanping>> listMap;
    public List<Baocunduanping> baocundianlist = new ArrayList<>();
    private Baocunduanping baocunduanping;
    private Map<Integer, List<Baocunduanping>> baocunpager = new HashMap<>();


    private String bookId;
    private List<Bookchapters.DataBean.ChapterInfoBean.ResultListBean> chaptersList;



    private OnReadStateChangeListener listener;
    private String charset = "UTF-8";
    private RectF oval3;
    private Rect vipSrcRect, vipDesRect;//VIP大图
    private Rect vipSrcRectzidong, vipDesRectzidong;//VIP自动
    private Rect vipSrcRectnozidong, vipDesRectnozidong;//VIP非自动
    private Rect authorImagesrcRect, authorImageDesRect, authorSaysrcRect, authorSayDesRect;//authorImagesrcRect作者头像显示本身大小，authorSaysrcRect作者的话背景显示本身大小，authorImageDesRect作者头像显示位置和尺寸

    private Rect mRect,mRectInvit;//VIP矩形渐变,mRectInvitvip中邀请好友

    // GradientDrawable支持使用渐变色来绘制图形，通常可以用作Button或是背景图形
    private GradientDrawable mDrawable;
    private String chaptertext = "";
    private RectF rectF1;//订阅按钮

    private String vipfisttext;
    private String viptishi = "本章是VIP章节，需购买后才能阅读";
    private String viptzidong = "自动购买下一章，不再提醒";
    private String viptbuy = "购买本章";
    private String vipInvit="领券免费看>>";
    public boolean isSelectzidong = true;
    private ReadBaocunBean readBaocunBean;
    private boolean isShowAuthersay = false;
    private boolean islastauthor = false;//是不是最后一页都显示的作者的话


    public PageFactory(Context context, String bookId, List<Bookchapters.DataBean.ChapterInfoBean.ResultListBean> chaptersList, ReadBaocunBean readBaocunBean) {
        this(context, ScreenUtils.getScreenWidth(context), ScreenUtils.getScreenHeight(context),
                SettingManager.getInstance().getReadFontSize(context, bookId),
                bookId, chaptersList, readBaocunBean);
    }

    public PageFactory(Context context, int width, int height, int fontSize, String bookId,
                       List<Bookchapters.DataBean.ChapterInfoBean.ResultListBean> chaptersList, ReadBaocunBean readBaocunBean) {
        this.readBaocunBean = readBaocunBean;
        mContext = context;
        daWidth = width;
        mWidth = width * 391 / 414;
        mHeight = height;
        mFontSize = fontSize;
        intView();
        this.bookId = bookId;
        this.chaptersList = chaptersList;
    }

    private void intView() {
        mLineSpace = mFontSize;
        mNumFontSize = mFontSize*7/8;
        marginWidth = ScreenUtils.getNum(mContext, 14);
        marginHeight = ScreenUtils.getNum(mContext, 18);
        mBookPageBg = Bitmap.createBitmap(daWidth, mHeight, Bitmap.Config.RGB_565);
        mVisibleHeight = mHeight - marginHeight * 3 - mNumFontSize * 2;
        mVisibleWidth = mWidth - marginWidth * 2;
        mPageLineCount = mVisibleHeight / (mFontSize + mLineSpace);
        rectF = new Rect(0, 0, daWidth, mHeight);
        mPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
        mPaint.setTextSize(mFontSize);

        authorPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
        authorPaint.setTextSize(ScreenUtils.getNum(mContext, 12));
        authorPaint.setColor(0xff999999);
        mPaintVIP = new Paint(Paint.ANTI_ALIAS_FLAG);
        mPaintVIP.setTextSize(ScreenUtils.getNum(mContext, 12));
        mPaintyue = new Paint(Paint.ANTI_ALIAS_FLAG);
        mPaintyue.setTextSize(ScreenUtils.getNum(mContext, 16));
        mRectvip = new Paint();
        mPaintInvite=new Paint();
        mPaintInvite.setTextSize(ScreenUtils.getNum(mContext, 12));
        mPaintInvite.setColor(0xff4A90E2);
        mTitlePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
        mdiannum = new Paint(Paint.ANTI_ALIAS_FLAG);
        mchapterPage = new Paint(Paint.ANTI_ALIAS_FLAG);
        mTitlePaint.setTextSize(mNumFontSize);
        mchapterPage.setTextSize(mFontSize * 5 / 4);
        mdiannum.setTextSize(ScreenUtils.getNum(mContext, 12));
        mRect = new Rect(0, mHeight / 3 - ScreenUtils.getNum(mContext, 50), daWidth, mHeight / 3 + ScreenUtils.getNum(mContext, 50));
        mPaintVIPbuy = new Paint(Paint.ANTI_ALIAS_FLAG);
        mPaintVIPbuy.setColor(0xffffffff);
        mPaintVIPbuy.setTextSize(ScreenUtils.getNum(mContext, 16));

        rectF1 = new RectF(ScreenUtils.getNum(mContext, 82), mHeight - ScreenUtils.getNum(mContext, 150), daWidth - ScreenUtils.getNum(mContext, 82), mHeight - ScreenUtils.getNum(mContext, 110));
        vipPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
        vipPaint.setColor(0xfff77583);
        //作者的话图
        authorImageBitmap = BitmapFactory.decodeResource(mContext.getResources(), R.mipmap.oval);
        authorbackBitmap = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.authorsay);
        authorNum = mVisibleWidth * authorbackBitmap.getHeight() / authorbackBitmap.getWidth() + ScreenUtils.getNum(mContext, 30);
        //作者头像
        authorImagesrcRect = new Rect(0, 0, authorImageBitmap.getWidth(), authorImageBitmap.getHeight());
        authorSaysrcRect = new Rect(0, 0, authorbackBitmap.getWidth(), authorbackBitmap.getHeight());
        authorImageDesRect = new Rect();
        authorSayDesRect = new Rect();
        //vip大图
        bitmapvip = BitmapFactory.decodeResource(mContext.getResources(), R.mipmap.recharge);
        vipSrcRect = new Rect(0, 0, bitmapvip.getWidth(), bitmapvip.getHeight());
        vipDesRect = new Rect((daWidth - ScreenUtils.getNum(mContext, 100)) / 2, mHeight / 3 + ScreenUtils.getNum(mContext, 100), (daWidth + ScreenUtils.getNum(mContext, 100)) / 2, mHeight / 3 + ScreenUtils.getNum(mContext, 260));
        //vip自动
        iszidongVip = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.selectzidong);
        zidongBitmapWight = (int) ((daWidth - mPaintVIP.measureText(viptzidong) - ScreenUtils.getNum(mContext, 30)) / 2);
        zidongBitmapHeight = mHeight - ScreenUtils.getNum(mContext, 94);
        vipSrcRectzidong = new Rect(0, 0, iszidongVip.getWidth(), iszidongVip.getHeight());
        vipDesRectzidong = new Rect(zidongBitmapWight, zidongBitmapHeight, zidongBitmapWight + ScreenUtils.getNum(mContext, 20), zidongBitmapHeight + ScreenUtils.getNum(mContext, 20));
        //vip非自动
        nozidongVip = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.normasel);
        vipSrcRectnozidong = new Rect(0, 0, nozidongVip.getWidth(), nozidongVip.getHeight());
        vipDesRectnozidong = new Rect(zidongBitmapWight, zidongBitmapHeight, zidongBitmapWight + ScreenUtils.getNum(mContext, 20), zidongBitmapHeight + ScreenUtils.getNum(mContext, 20));
        oval3 = new RectF(daWidth - ScreenUtils.getNum(mContext, 23), marginHeight, daWidth - ScreenUtils.getNum(mContext, 25), mHeight - marginHeight);
        dianchi = new Rect(marginWidth, mHeight - marginHeight - ScreenUtils.getNum(mContext, 12), marginWidth + ScreenUtils.getNum(mContext, 24), mHeight - marginHeight + ScreenUtils.getNum(mContext, 2));
        mTitlePaint.setColor(ContextCompat.getColor(AppUtils.getAppContext(), R.color.chapter_title_day));
        mdiannum.setColor(Color.parseColor("#ffffff"));
        timeLen = (int) mTitlePaint.measureText("00:00");
        percentLen = (int) mTitlePaint.measureText("00.00%");
        mDuanpingPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
        mDuanpingPaint.setStrokeWidth(ScreenUtils.getNum(mContext, 2));
        mpark = new Paint(Paint.ANTI_ALIAS_FLAG);
        smallmpark = new Paint(Paint.ANTI_ALIAS_FLAG);
        if (SettingManager.getInstance().getIsNightDay() == 1) {
            setBeijing(readBeijingBean.getBeijingcolort().size() - 1);
        } else {
            setBeijing(SettingManager.getInstance().getBeijingcolor());
        }
        // 设置Drawable的形状为矩形
        mDrawable.setShape(GradientDrawable.RECTANGLE);
    }


    /**
     * 打开书籍文件
     *
     * @param chapter  阅读章节
     * @param position 阅读位置
     * @return 0：文件不存在或打开失败  1：打开成功
     */
    public int openBook(int chapter, int[] position) {
        islastauthor = false;
        this.currentChapter = chapter;
        this.chapterSize = chaptersList.size();
        if (currentChapter > chapterSize) {
            currentChapter = chapterSize;
        }
        //String path = getBookFile(currentChapter).getPath();
        //String path=Reading2Activity.path.replaceAll("<LG>[a-zA-Z\\d-]{36}<LG>","\n    ");
        try {
            if (readBaocunBean.getContextMap().get(currentChapter) == null) {
                return 0;
            }
        } catch (Exception e) {
            e.printStackTrace();
            return 0;
        }
        byte[] path = readBaocunBean.getContextMap().get(currentChapter).getContext();

        int length = path.length;

        mbBufferLen = length;
        // 创建文件通道，映射为ByteBuffer
        mbBuff = ByteBuffer.wrap(path);
        curBeginPos = position[0];
        curEndPos = position[1];
        if (curEndPos > mbBufferLen || curBeginPos > mbBufferLen) {
            SettingManager.getInstance().saveReadProgress(bookId, currentChapter, 0, 0, 1, 0);
            return 0;
        }
        if (currentChapter == 0 && position[2] == 0) {
            currentPage = 1;
        } else {
            currentPage = position[2];
        }
        baocundiannum = position[3];
        mLines.clear();
        baocunpager = new HashMap<>();
        baocundianlist = new ArrayList<>();
        //onChapterChanged(chapter);
        return 1;
    }

    /**
     * 绘制阅读页面
     *
     * @param canvas
     */
    public synchronized void onDraw(Canvas canvas) {
        if (mLines.size() == 0) {
            //curEndPos = curBeginPos;
            mLines = pageDown();
            Log.v("drawgo", "go");
        }
        isShowAuthersay = false;
        if (mLines.size() > 0) {
            int y = marginHeight;
            // 绘制背景
            if (mBookPageBg != null) {
                canvas.drawBitmap(mBookPageBg, null, rectF, null);
            } else {
                canvas.drawColor(Color.WHITE);
            }
            // 绘制标题,如果是第一页写书名，其余页写章节名
            if (currentPage == 1) {
                canvas.drawText(chaptersList.get(currentChapter).getBookTitle(), marginWidth, y * 3 / 2, mTitlePaint);
            } else {
                canvas.drawText(chaptersList.get(currentChapter).getChapterTitle(), marginWidth, y * 3 / 2, mTitlePaint);
            }
            y += mLineSpace + mNumFontSize;
            canvas.drawRoundRect(oval3, 20, 15, mDuanpingPaint);
            // 绘制阅读页面文字
            //listMap.put()
            //readBaocunBean.getContextMap().get(currentChapter).setBaocunyeshu(currentPage);
            int quchudian = 0;
            int pagelin = 1;
            for (String line : mLines) {
                y += mLineSpace;
                if (line.endsWith("@")) {
                    canvas.drawText(line.substring(0, line.length() - 1), marginWidth, y, mPaint);
                    mpark.setAntiAlias(true);// 设置画笔的锯齿效果。 true是去除，大家一看效果就明白了

                    try {
                        if (quchudian < readBaocunBean.getContextMap().get(currentChapter).getBaocunyeshu().get(currentPage).size() - 1) {
                            baocunduanping = readBaocunBean.getContextMap().get(currentChapter).getBaocunyeshu().get(currentPage).get(quchudian);
                            if (baocunduanping.getCount() != 0) {
                                canvas.drawCircle(daWidth - ScreenUtils.getNum(mContext, 24), y - mLineSpace / 2, ScreenUtils.getNum(mContext, 10), mpark);
                                if (baocunduanping.getCount() >= 99) {
                                    canvas.drawText("99+", daWidth - ScreenUtils.getNum(mContext, 24) - mdiannum.measureText("99+") / 2, y - mLineSpace / 2 + ScreenUtils.getNum(mContext, 3), mdiannum);
                                } else {
                                    canvas.drawText(String.valueOf(baocunduanping.getCount()), daWidth - ScreenUtils.getNum(mContext, 24) - mdiannum.measureText(String.valueOf(baocunduanping.getCount())) / 2, y - mLineSpace / 2 + ScreenUtils.getNum(mContext, 6), mdiannum);
                                }
                            } else {
                                canvas.drawCircle(daWidth - ScreenUtils.getNum(mContext, 24), y - mLineSpace / 2, ScreenUtils.getNum(mContext, 7), smallmpark);
                            }
                            baocunduanping.setLeftx(daWidth - ScreenUtils.getNum(mContext, 24) - ScreenUtils.getNum(mContext, 10));
                            baocunduanping.setLety(y - ScreenUtils.getNum(mContext, 20));
                            baocunduanping.setYuanweight(daWidth - ScreenUtils.getNum(mContext, 24) + ScreenUtils.getNum(mContext, 20));
                            baocunduanping.setYuanheight(y);
                            baocunduanping.setChaptertext(chaptertext + line.substring(0, line.length() - 2));
                            chaptertext = "";
                            //y+=mLineSpace;
                            quchudian++;
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                } else {
                    Log.v("pagefactory",pagelin+"---"+currentPage);
                    if (pagelin == 1 && currentPage == 1) {
                        canvas.drawText(line, (mVisibleWidth - mchapterPage.measureText(line)) / 2 + marginWidth, y, mchapterPage);
                        y =y+ mFontSize / 4+mLineSpace/4;
                    } else {
                        canvas.drawText(line, marginWidth, y, mPaint);
                        chaptertext += line;
                    }

                }
                pagelin++;
                y += mFontSize;
            }
            //绘制作者的话
            if (y < mVisibleHeight - authorNum) {
                toDrawAuthorSay(y, canvas);
            }
            //绘制vip
            toDrawVip(canvas);
            //绘制进度
            canvas.drawText(decimalFormat.format((float) 100 * curEndPos / mbBufferLen) + "%", (daWidth - percentLen) / 2, mHeight - marginHeight, mTitlePaint);
            //绘制电池和时间
            drawtimeandBattery(canvas);
        } else {
            int y = marginHeight;

            // 绘制背景
            if (mBookPageBg != null) {
                canvas.drawBitmap(mBookPageBg, null, rectF, null);
            } else {
                canvas.drawColor(Color.WHITE);
            }
            // 绘制标题,如果是第一页写书名，其余页写章节名
            if (currentPage == 1) {
                canvas.drawText(chaptersList.get(currentChapter).getBookTitle(), marginWidth, y * 3 / 2, mTitlePaint);
            } else {
                canvas.drawText(chaptersList.get(currentChapter).getChapterTitle(), marginWidth, y * 3 / 2, mTitlePaint);
            }
            y += mLineSpace + mNumFontSize;
            canvas.drawRoundRect(oval3, 20, 15, mDuanpingPaint);

            //绘制作者的话
            toDrawAuthorSay(y, canvas);
            Log.v("drawislast", islastauthor + "");
            islastauthor = true;
            //绘制进度
            float percent = (float) 100 * curEndPos / mbBufferLen;
            canvas.drawText(decimalFormat.format(percent) + "%", (daWidth - percentLen) / 2,
                    mHeight - marginHeight, mTitlePaint);
            //绘制电池和时间
            drawtimeandBattery(canvas);
        }
    }



    /**
     * 指针移到上一页页首
     */
    private void pageUp() {
        String strParagraph = "";
        Vector<String> lines = new Vector<>(); // 页面行
        int paraSpace = 0;
        mPageLineCount = mVisibleHeight / (mFontSize + mLineSpace);

        try {
            if (baocundiannum - (readBaocunBean.getContextMap().get(currentChapter).getBaocunyeshu().get(currentPage).size()) > 0) {
                baocundiannum = baocundiannum - (readBaocunBean.getContextMap().get(currentChapter).getBaocunyeshu().get(currentPage).size());
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        if ((lines.size() < mPageLineCount) && (curBeginPos > 0) && mbBuff.get(curBeginPos - 1) == 0x0a) {
            baocundiannum--;
        }
        while ((lines.size() < mPageLineCount) && (curBeginPos > 0)) {
            Vector<String> paraLines = new Vector<>();// 段落行
            byte[] parabuffer = readParagraphBack(curBeginPos); // 1.读取上一个段落

            curBeginPos -= parabuffer.length; // 2.变换起始位置指针
            try {
                strParagraph = new String(parabuffer, charset);
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
            strParagraph = strParagraph.replaceAll("\n", " ");
            while (strParagraph.length() > 0) { // 3.逐行添加到lines
                int paintSize = mPaint.breakText(strParagraph, true, mVisibleWidth, null);
                paraLines.add(strParagraph.substring(0, paintSize));
                strParagraph = strParagraph.substring(paintSize);
            }
            lines.addAll(0, paraLines);
            if (lines.size() >= mPageLineCount) {
                baocundiannum++;
            }
            while (lines.size() > mPageLineCount) { // 4.如果段落添加完，但是超出一页，则超出部分需删减
                try {
                    curBeginPos += lines.get(0).getBytes(charset).length; // 5.删减行数同时起始位置指针也要跟着偏移
                    lines.remove(0);
                } catch (UnsupportedEncodingException e) {
                    e.printStackTrace();
                }
            }

            // curEndPos = curBeginPos; // 6.最后结束指针指向下一段的开始处
            //paraSpace += mLineSpace;
            mPageLineCount = mVisibleHeight / (mFontSize + mLineSpace); // 添加段落间距，实时更新容纳行数
        }
    }

    /**
     * 根据起始位置指针，读取一页内容
     *
     * @return
     */
    private Vector<String> pageDown() {
        String strParagraph = "";
        Vector<String> lines = new Vector<>();
        int paraSpace = 0;

        if (currentPage == 1) {
            mPageLineCount = (mVisibleHeight - mFontSize/4-mLineSpace/4) / (mFontSize + mLineSpace);
            lines.add(chaptersList.get(currentChapter).getChapterTitle());
        } else {
            mPageLineCount = mVisibleHeight / (mFontSize + mLineSpace);
        }

        while ((lines.size() < mPageLineCount) && (curEndPos < mbBufferLen)) {
            byte[] parabuffer = readParagraphForward(curEndPos);
            curEndPos += parabuffer.length;
            try {
                strParagraph = new String(parabuffer, charset);
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
            strParagraph = strParagraph
                    .replaceAll("\n", " "); // 段落中的换行符去掉，绘制的时候再换行
            while (strParagraph.length() > 0) {
                int paintSize = mPaint.breakText(strParagraph, true, mVisibleWidth, null);
                lines.add(strParagraph.substring(0, paintSize));
                strParagraph = strParagraph.substring(paintSize);
                if (lines.size() >= mPageLineCount) {
                    break;
                }
            }
            if (strParagraph.length() > 0 && lines.size() >= mPageLineCount) {

            } else {
                lines.set(lines.size() - 1, lines.get(lines.size() - 1) + "@");
                toAdddian();
            }
            if (strParagraph.length() != 0) {
                try {
                    curEndPos -= (strParagraph).getBytes(charset).length;
                } catch (UnsupportedEncodingException e) {
                    e.printStackTrace();
                }
            }
            //paraSpace += mLineSpace;
            mPageLineCount = mVisibleHeight / (mFontSize + mLineSpace);
        }
        baocunpager.put(currentPage, baocundianlist);
        try {
            readBaocunBean.getContextMap().get(currentChapter).setBaocunyeshu(baocunpager);
        } catch (Exception e) {
            e.printStackTrace();
        }
        baocundianlist = new ArrayList<>();
        return lines;
    }

    private void toAdddian() {
        baocundiannum++;
        try {
            if (baocundiannum > readBaocunBean.getContextMap().get(currentChapter).getDianlist().size()) {
                baocunduanping = new Baocunduanping();
                baocunduanping.setCount(0);
            } else {
                baocunduanping = new Baocunduanping();
                baocunduanping.setUuid(readBaocunBean.getContextMap().get(currentChapter).getDianlist().get(baocundiannum - 1));
                if (readBaocunBean.getContextMap().get(currentChapter).getCountnum() != null) {
                    for (ChapterContext.DataBean.CountInfosBean diancountbean : readBaocunBean.getContextMap().get(currentChapter).getCountnum()
                            ) {
                        if (diancountbean.getPid().equals(baocunduanping.getUuid())) {
                            baocunduanping.setCount(diancountbean.getCount());
                            break;
                        }
                        baocunduanping.setCount(0);
                    }
                } else {
                    baocunduanping.setCount(0);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        baocundianlist.add(baocunduanping);
    }

    /**
     * 获取最后一页的内容。比较繁琐，待优化
     *
     * @return
     */
    public Vector<String> pageLast() {
        String strParagraph = "";
        Vector<String> lines = new Vector<>();
        currentPage = 0;
        baocundiannum = 0;
        while (curEndPos < mbBufferLen) {
            int paraSpace = 0;
            if (currentPage == 0) {
                mPageLineCount = (mVisibleHeight - mFontSize/4-mLineSpace/4) / (mFontSize + mLineSpace);
                lines.add(chaptersList.get(currentChapter).getChapterTitle());
            } else {
                mPageLineCount = mVisibleHeight / (mFontSize + mLineSpace);
            }
            curBeginPos = curEndPos;
            while ((lines.size() < mPageLineCount) && (curEndPos < mbBufferLen)) {
                byte[] parabuffer = readParagraphForward(curEndPos);
                curEndPos += parabuffer.length;
                try {
                    strParagraph = new String(parabuffer, charset);
                } catch (UnsupportedEncodingException e) {
                    e.printStackTrace();
                }
                strParagraph = strParagraph.replaceAll("\n", " ");// 段落中的换行符去掉，绘制的时候再换行
                while (strParagraph.length() > 0) {
                    int paintSize = mPaint.breakText(strParagraph, true, mVisibleWidth, null);
                    lines.add(strParagraph.substring(0, paintSize));
                    strParagraph = strParagraph.substring(paintSize);
                    if (lines.size() >= mPageLineCount) {
                        break;
                    }
                }
                if (strParagraph.length() > 0 && lines.size() >= mPageLineCount) {

                } else {
                    lines.set(lines.size() - 1, lines.get(lines.size() - 1) + "@");
                    toAdddian();

                }

                if (strParagraph.length() != 0) {
                    try {
                        curEndPos -= (strParagraph).getBytes(charset).length;
                    } catch (UnsupportedEncodingException e) {
                        e.printStackTrace();
                    }
                }
                /*paraSpace += mLineSpace;*/
                mPageLineCount = mVisibleHeight / (mFontSize + mLineSpace);
            }
            if (curEndPos < mbBufferLen) {
                lines.clear();
            }
            currentPage++;
            baocunpager.put(currentPage, baocundianlist);
            readBaocunBean.getContextMap().get(currentChapter).setBaocunyeshu(baocunpager);
            baocundianlist = new ArrayList<>();
        }
        /*
         * 留出位置放作者的话
         * */
        if (!isShowAuthersay) {
            if (currentPage == 0) {
                mPageLineCount = (mVisibleHeight - mFontSize/4-mLineSpace/4 - authorNum) / (mFontSize + mLineSpace);
            } else {
                mPageLineCount = (mVisibleHeight - authorNum) / (mFontSize + mLineSpace);
            }
            if (lines.size() > mPageLineCount) {
                currentPage++;
                Log.v("drawislastss", islastauthor + "");
                islastauthor = true;
            }
        }

        Log.v("draw7", lines.size() + "");
        //SettingManager.getInstance().saveReadProgress(bookId, currentChapter, curBeginPos, curEndPos);
        return lines;
    }

    /**
     * 读取下一段落
     *
     * @param curEndPos 当前页结束位置指针
     * @return
     */
    private byte[] readParagraphForward(int curEndPos) {
        byte b0;
        int i = curEndPos;
        while (i < mbBufferLen) {
            b0 = mbBuff.get(i++);
            if (b0 == 0x0a && i != curEndPos) {
                break;
            }
        }
        int nParaSize = i - curEndPos;
        byte[] buf = new byte[nParaSize];
        for (i = 0; i < nParaSize; i++) {
            buf[i] = mbBuff.get(curEndPos + i);
        }
        return buf;
    }

    /**
     * 读取上一段落
     *
     * @param curBeginPos 当前页起始位置指针
     * @return
     */
    private byte[] readParagraphBack(int curBeginPos) {
        byte b0;
        int i = curBeginPos - 1;
        while (i > 0) {
            b0 = mbBuff.get(i);
            if (b0 == 0x0a && i != curBeginPos - 1) {
                i++;
                baocundiannum--;
                break;
            }
            i--;
        }
        int nParaSize = curBeginPos - i;
        byte[] buf = new byte[nParaSize];
        for (int j = 0; j < nParaSize; j++) {
            buf[j] = mbBuff.get(i + j);
        }
        return buf;
    }

    /**
     * 读取下一段落不超过当前位置
     *
     * @param curEndPos 当前页结束位置指针
     * @return
     */
    private byte[] readParagraphForwardnow(int curEndPos) {
        byte b0;
        int i = curEndPos;
        while (i < mbBufferLen) {
            b0 = mbBuff.get(i++);
            if (b0 == 0x0a && i != curEndPos) {
                break;
            }
        }
        int nParaSize = i - curEndPos;
        byte[] buf = new byte[nParaSize];
        for (i = 0; i < nParaSize; i++) {
            buf[i] = mbBuff.get(curEndPos + i);
        }
        return buf;
    }

    public boolean hasNextPage() {
        return currentChapter < chaptersList.size() - 1 ||( curEndPos < mbBufferLen&&!isVip());
    }

    public boolean hasPrePage() {
        return currentChapter > 0 || (currentChapter == 0 && curBeginPos > 0);
    }

    /**
     * 跳转下一页
     */
    public BookStatus nextPage() {
        if (!hasNextPage()) { // 最后一章
            // 的结束页
           listener.isOverPage();
            return BookStatus.NO_NEXT_PAGE;
        } else {
            tempChapter = currentChapter;
            tempPage = currentPage;
            tempBeginPos = curBeginPos;
            tempEndPos = curEndPos;
            if ((curEndPos >= mbBufferLen && isShowAuthersay) || isVip()) { // 中间章节结束页&&作者的话是否显示

                currentChapter++;
                isShowAuthersay = false;
                int ret = openBook(currentChapter, new int[]{0, 0, 0, 0}); // 打开下一章
                if (ret == 0) {
                    onLoadChapterFailure(currentChapter);
                    currentChapter--;
                    curBeginPos = tempBeginPos;
                    curEndPos = tempEndPos;
                    return BookStatus.NEXT_CHAPTER_LOAD_FAILURE;
                } else {
                    currentPage = 0;
                    onChapterChanged(currentChapter);
                }
            } else {
                curBeginPos = curEndPos; // 起始指针移到结束位置
            }

            mLines.clear();
            currentPage++;
            mLines = pageDown(); // 读取一页内容
            onPageChanged(currentChapter, currentPage);
        }
        return BookStatus.LOAD_SUCCESS;
    }

    /**
     * 跳转上一页
     */
    public BookStatus prePage() {
        if (!hasPrePage()) { // 第一章第一页
            return BookStatus.NO_PRE_PAGE;
        } else {
            // 保存当前页的值
            tempChapter = currentChapter;
            tempPage = currentPage;
            tempBeginPos = curBeginPos;
            tempEndPos = curEndPos;
            if (curBeginPos <= 0) {
                currentChapter--;
                int ret = openBook(currentChapter, new int[]{0, 0, 0, 0});
                if (ret == 0) {
                    onLoadChapterFailure(currentChapter);
                    currentChapter++;
                    return BookStatus.PRE_CHAPTER_LOAD_FAILURE;
                } else { // 跳转到上一章的最后一页
                    mLines.clear();
                    mLines = pageLast();
                    if (islastauthor) {
                        mLines.clear();
                        curBeginPos = curEndPos;
                    }
                    onChapterChanged(currentChapter);
                    //onPageChanged(currentChapter, currentPage);
                    return BookStatus.LOAD_SUCCESS;
                }
            }

            if (isShowAuthersay && islastauthor) {
                mLines.clear();
                curEndPos = 0;
                curBeginPos = 0;
                mLines = pageLast();
                isShowAuthersay = false;
                Log.v("drawhehe", mLines + "begin" + curBeginPos + "end" + curEndPos + "page" + currentPage);
                onPageChanged(currentChapter, currentPage);
                return BookStatus.LOAD_SUCCESS;
            }
            pageUp(); // 起始指针移到上一页开始处
            curEndPos = curBeginPos;
            mLines.clear();
            currentPage--;
            mLines = pageDown(); // 读取一页内容
            Log.v("drawtt", mLines + "begin" + curBeginPos + "end" + curEndPos + "page" + currentPage);
            onPageChanged(currentChapter, currentPage);
        }
        return BookStatus.LOAD_SUCCESS;
    }

    /*
     * 跳转到当前
     * */
    public void topagenow() {
        String strParagraph = "";
        Log.v("pagefactory",currentPage+"--");
       currentPage=currentPage>1?1:currentPage;


        baocundiannum = 0;
        curEndPos = 0;
        int hangnum = 0;
        int paintSize;
        while (curEndPos < curBeginPos) {
            if (currentPage == 0) {
                mPageLineCount = (mVisibleHeight - mFontSize/4-mLineSpace/4) / (mFontSize + mLineSpace);
                hangnum++;
            } else {
                mPageLineCount = mVisibleHeight / (mFontSize + mLineSpace);
            }
            while ((hangnum < mPageLineCount) && curEndPos < curBeginPos) {
                byte[] parabuffer = readParagraphForwardnow(curEndPos);
                curEndPos += parabuffer.length;
                try {
                    strParagraph = new String(parabuffer, charset);
                } catch (UnsupportedEncodingException e) {
                    e.printStackTrace();
                }
                strParagraph = strParagraph.replaceAll("\r\n", "").replaceAll("\n", "");// 段落中的换行符去掉，绘制的时候再换行
                while (strParagraph.length() > 0) {
                    paintSize = mPaint.breakText(strParagraph, true, mVisibleWidth, null);
                    hangnum++;
                    strParagraph = strParagraph.substring(paintSize);
                    if (hangnum >= mPageLineCount) {
                        break;
                    }
                }
                if (!(strParagraph.length() > 0 || curEndPos > curBeginPos)) {
                    baocundiannum++;
                }

                if (strParagraph.length() != 0) {
                    try {
                        curEndPos -= (strParagraph).getBytes(charset).length;
                    } catch (UnsupportedEncodingException e) {
                        e.printStackTrace();
                    }
                }
                /*paraSpace += mLineSpace;*/

            }
            if (curEndPos < mbBufferLen) {
                hangnum = 0;
            }
            currentPage++;
        }
        //SettingManager.getInstance().saveReadProgress(bookId, currentChapter, curBeginPos, curEndPos);
        curEndPos = curBeginPos;
    }


    /*public void cancelPage() {
     *//*currentChapter = tempChapter;
        curBeginPos = tempBeginPos;
        curEndPos = curBeginPos;
        int ret = openBook(currentChapter, new int[]{curBeginPos, curEndPos,currentPage,baocundiannum-readBaocunBean.getContextMap().get(currentChapter).getBaocunyeshu().size()});
        if (ret == 0) {
            onLoadChapterFailure(currentChapter);
            return;
        }
        mLines.clear();
        mLines = pageDown();*//*
    }
*/

    /**
     * 获取当前阅读位置
     *
     * @return index 0：起始位置 1：结束位置
     */
    public int[] getPosition() {
        try {
            return new int[]{currentChapter, curBeginPos, curEndPos, currentPage, baocundiannum - readBaocunBean.getContextMap().get(currentChapter).getBaocunyeshu().get(currentPage).size()};
        } catch (Exception e) {
            e.printStackTrace();
        }
        return new int[]{currentChapter, 0, 0, 1, 0};
    }

    public String getHeadLineStr() {
        if (mLines != null && mLines.size() > 1) {
            if (currentPage == 1) {
                return mLines.get(1);
            }
            return mLines.get(0);
        }
        return "";
    }

    /**
     * 设置字体大小
     *
     * @param fontsize 单位：px
     */
    public void setTextFont(int fontsize) {
        LogUtils.i("fontSize=" + fontsize);
        mFontSize = fontsize;
        mNumFontSize=mFontSize*7/8;
        mLineSpace = mFontSize;
        mPaint.setTextSize(mFontSize);
        mTitlePaint.setTextSize(mNumFontSize);
        mchapterPage.setTextSize(mFontSize * 5 / 4);
        currentPage=0;
        topagenow();
        if (isVip()){
            currentChapter--;
        }
        nextPage();
    }

    public void setBeijing(int position) {
        LogUtils.i("fontSize=" + position);
        mPaint.setColor(Color.parseColor(readBeijingBean.getZiticolort().get(position)));
        mPaintVIP.setColor(Color.parseColor(readBeijingBean.getZiticolort().get(position)));
        mchapterPage.setColor(Color.parseColor(readBeijingBean.getZiticolort().get(position)));
        mpark.setColor(Color.parseColor(readBeijingBean.getYuancolor().get(position)));
        smallmpark.setColor(Color.parseColor(readBeijingBean.getSmallyuancolor().get(position)));
        mDuanpingPaint.setColor(Color.parseColor(readBeijingBean.getLinecolor().get(position)));
        mBookPageBg.eraseColor(readBeijingBean.getVipbeijing().get(position));
        mDrawable = new GradientDrawable(
                GradientDrawable.Orientation.TOP_BOTTOM, new int[]{readBeijingBean.getVipjianbian().get(position),
                readBeijingBean.getVipbeijing().get(position)});
        mRectvip.setColor(readBeijingBean.getVipbeijing().get(position));
        SettingManager.getInstance().saveBeijingcolor(position);
        //修改作者的话图
        if (position == readBeijingBean.getBeijingcolort().size() - 1) {
            authorbackBitmap = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.authorsayneight);
            authorPaint.setColor(0xff798795);
        } else {
            authorbackBitmap = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.authorsay);
            authorPaint.setColor(0xff999999);
        }

    }

    /**
     * 设置字体颜色
     *
     * @param textColor
     * @param titleColor
     */
    public void setTextColor(int textColor, int titleColor) {
        mPaint.setColor(textColor);
        mTitlePaint.setColor(titleColor);
    }

    public int getTextFont() {
        return mFontSize;
    }

    /**
     * 根据百分比，跳到目标位置
     *
     * @param persent
     */
    public void setPercent(int persent) {
        float a = (float) (mbBufferLen * persent) / 100;
        curEndPos = (int) a;
        if (curEndPos == 0) {
            nextPage();
        } else {
            nextPage();
            prePage();
            nextPage();
        }
    }

    public void setBgBitmap(Bitmap BG) {
        mBookPageBg = BG;
    }

    public void setOnReadStateChangeListener(OnReadStateChangeListener listener) {
        this.listener = listener;
    }

    private void onChapterChanged(int chapter) {
        if (listener != null)
            listener.onChapterChanged(chapter);
    }

    private void onPageChanged(int chapter, int page) {
        if (listener != null)
            listener.onPageChanged(chapter, page);
    }

    private void onLoadChapterFailure(int chapter) {
        if (listener != null)
            listener.onLoadChapterFailure(chapter);
    }

    public void convertBetteryBitmap() {
        batteryView = (ProgressBar) LayoutInflater.from(mContext).inflate(R.layout.layout_battery_progress, null);
        batteryView.setProgressDrawable(ContextCompat.getDrawable(mContext,
                SettingManager.getInstance().getIsNightDay() == 0 ?
                        R.drawable.seekbar_battery_bg : R.drawable.seekbar_battery_night_bg));
        batteryView.setProgress(battery);
        batteryView.setDrawingCacheEnabled(true);
        batteryView.measure(View.MeasureSpec.makeMeasureSpec(ScreenUtils.getNum(mContext, 24), View.MeasureSpec.UNSPECIFIED),
                View.MeasureSpec.makeMeasureSpec(ScreenUtils.getNum(mContext, 14), View.MeasureSpec.UNSPECIFIED));
        batteryView.layout(0, 0, batteryView.getMeasuredWidth(), batteryView.getMeasuredHeight());
        batteryView.buildDrawingCache();
        //batteryBitmap = batteryView.getDrawingCache();
        // tips: @link{https://github.com/JustWayward/BookReader/issues/109}
        batteryBitmap = Bitmap.createBitmap(batteryView.getDrawingCache());
        batteryView.setDrawingCacheEnabled(false);
        batteryView.destroyDrawingCache();
    }

    public void setBattery(int battery) {
        this.battery = battery;
        convertBetteryBitmap();
    }


    public void recycle() {
        if (mBookPageBg != null && !mBookPageBg.isRecycled()) {
            mBookPageBg.recycle();
            mBookPageBg = null;
            System.gc();
            System.runFinalization();
            System.gc();
            LogUtils.d("mBookPageBg recycle");
        }

        if (batteryBitmap != null && !batteryBitmap.isRecycled()) {
            batteryBitmap.recycle();
            batteryBitmap = null;
            System.gc();
            System.runFinalization();
            System.gc();
            LogUtils.d("batteryBitmap recycle");
        }
    }

    public void toBackpage() {
        if (tempChapter > currentChapter) {
            nextPage();
        } else if (tempChapter == currentChapter) {
            if (tempPage > currentPage) {
                nextPage();
            } else if (tempPage < currentPage) {
                prePage();
            }
        } else {
            prePage();
        }
    }

    //获取本章是否VIP
    public boolean isVip() {

        try {
            return readBaocunBean.getContextMap().get(currentChapter).isVip();
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }

    }

    /*
     * 只绘制时间和电池
     * */
    public void drawtimeandBattery(Canvas canvas) {
        // 绘制电池
        if (batteryBitmap != null) {
            canvas.drawBitmap(batteryBitmap, null,
                    dianchi, mTitlePaint);
        }
        canvas.drawText(dateFormat.format(new Date()), timeLen + ScreenUtils.getNum(mContext, 6), mHeight - marginHeight, mTitlePaint);
    }

    /*
     * 修改作者图片
     * */
    public void setauthorImage(Bitmap bitmap) {
        authorImageBitmap = bitmap;
        authorImagesrcRect = new Rect(0, 0, authorImageBitmap.getWidth(), authorImageBitmap.getHeight());
    }
    //绘制VIP
    private void toDrawVip(Canvas canvas) {
        try {
            if (readBaocunBean.getContextMap().get(currentChapter).isVip()) {
                mDrawable.setBounds(mRect);
                // 设置渐变模式：线性渐变
                mDrawable.setGradientType(GradientDrawable.LINEAR_GRADIENT);
                mDrawable.draw(canvas);
                canvas.drawRect(0, mHeight / 3 + ScreenUtils.getNum(mContext, 50), daWidth, mHeight, mRectvip);
                canvas.drawRoundRect(rectF1, ScreenUtils.getNum(mContext, 30), ScreenUtils.getNum(mContext, 30), vipPaint);
                canvas.drawBitmap(bitmapvip, vipSrcRect, vipDesRect, null);
                canvas.drawText(vipInvit,(daWidth - mPaintInvite.measureText(vipInvit)) / 2,mHeight - ScreenUtils.getNum(mContext, 205),mPaintInvite);
                vipfisttext = "价格：" + chaptersList.get(currentChapter).getPrice() + "辣椒";
                viptishi = "余额:" + UserManageBean.userBean.getUserMoney() + "辣椒  " + UserManageBean.userBean.getUserReadTicket() + "辣椒券";
                canvas.drawText(viptbuy, (daWidth - mPaintVIPbuy.measureText(viptbuy)) / 2, mHeight - ScreenUtils.getNum(mContext, 128), mPaintVIPbuy);
                canvas.drawText(vipfisttext, (daWidth - mPaintyue.measureText(vipfisttext)) / 2, mHeight - ScreenUtils.getNum(mContext, 180), mPaintyue);
                canvas.drawText(viptishi, (daWidth - mPaintVIP.measureText(viptishi)) / 2, mHeight - ScreenUtils.getNum(mContext, 160), mPaintVIP);
                canvas.drawText(viptzidong, zidongBitmapWight + ScreenUtils.getNum(mContext, 30), zidongBitmapHeight + ScreenUtils.getNum(mContext, 14), mPaintVIP);
                if (isSelectzidong) {
                    canvas.drawBitmap(iszidongVip, vipSrcRectzidong, vipDesRectzidong, null);
                } else {
                    canvas.drawBitmap(nozidongVip, vipSrcRectnozidong, vipDesRectnozidong, null);
                }

            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    //绘制作者的的话
    private void toDrawAuthorSay(int y, Canvas canvas) {
        authorSayDesRect.set(marginWidth, y, mWidth - marginWidth, y + authorNum - ScreenUtils.getNum(mContext, 30));
        authorImageDesRect.set(ScreenUtils.getNum(mContext, 30), y + ScreenUtils.getNum(mContext, 50), ScreenUtils.getNum(mContext, 30 + authorImagerec), y + ScreenUtils.getNum(mContext, authorImagerec + 50));
        canvas.drawBitmap(authorbackBitmap, authorSaysrcRect, authorSayDesRect, null);
        canvas.drawBitmap(authorImageBitmap, authorImagesrcRect, authorImageDesRect, null);
        canvas.drawText(chaptersList.get(currentChapter).getBookTitle(), ScreenUtils.getNum(mContext, 40 + authorImagerec), y + ScreenUtils.getNum(mContext, 70), authorPaint);
        if (chaptersList.get(currentChapter).getAuthorWords()!=null){
            String strParagraph=chaptersList.get(currentChapter).getAuthorWords();
            int paintSize=0;
            int hangnum=0;
            int height=0;
            while (strParagraph.length() > 0&&hangnum<3) {
                paintSize = authorPaint.breakText(strParagraph, true, mWidth - marginWidth-ScreenUtils.getNum(mContext, 40 + authorImagerec), null);
                hangnum++;
                canvas.drawText(strParagraph.substring(0,paintSize), ScreenUtils.getNum(mContext, 40 + authorImagerec), y + ScreenUtils.getNum(mContext, 95)+height, authorPaint);
                strParagraph = strParagraph.substring(paintSize);
                height+=ScreenUtils.getNum(mContext,20);
            }
        }


        isShowAuthersay = true;
    }
    public int getZidongBitmapHeight(){
        return zidongBitmapHeight;
    }
    public int getZidongBitmapWight(){
        return zidongBitmapWight;
    }
}
